package palette;

import java.awt.BorderLayout;

import javax.swing.JInternalFrame;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import mainWindowSupport.ShapeExplorer;
import mainWindowSupport.ShapePropTable;
import mainWindowSupport.ShapeProperties;
import mainWindowSupport.ShapeTree;
import actionHandlers.CanvasListener;
import actionHandlers.IntCloseListener;
import java.awt.Container;
import java.awt.Dimension;

public class CanvasWindow extends JInternalFrame{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1179450035315166177L;
	//private PropertiesSidebar sidebar;
	
	Canvas myCanvas;
	//Create instance of ShapeExplorer
	ShapeExplorer shapeExpl;
	//JTree shapeTree = ShapeTree.getInst();
	ShapeProperties shapeProp;
	//Join the panes
	JSplitPane sidebarInfoPane;
	JSplitPane wholeAppPane;
	
	private ShapeTree shapeTree;
	private ShapePropTable shapeTable;
	
	public CanvasWindow(String name){
		super(name,true,true,true,true);
		//sidebar = new PropertiesSidebar();
		this.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
		this.addInternalFrameListener(new IntCloseListener());
		//myCanvas = new Canvas(sidebar);
		myCanvas = new Canvas();
		myCanvas.setPreferredSize(new Dimension(550,350));
		myCanvas.addComponentListener(new CanvasListener());
		
		JScrollPane scroll = new JScrollPane(myCanvas);
		scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
		scroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
		add(scroll);
		pack();
		setVisible(true);
		
		// moving properties to each canvas
		shapeTree = new ShapeTree();
		shapeTable = new ShapePropTable();
		shapeExpl = new ShapeExplorer();
		shapeProp = new ShapeProperties();
		sidebarInfoPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, shapeExpl.getPane(), shapeProp.getPane());
		sidebarInfoPane.setDividerLocation(198);
				
		shapeProp.setShapeTable(shapeTable);
		shapeExpl.setShapeTree(shapeTree);
		

		
		wholeAppPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, sidebarInfoPane, myCanvas);
		wholeAppPane.setDividerLocation(175);

		
		Container contentPane = getContentPane();
		contentPane.add(wholeAppPane, BorderLayout.CENTER);
	}
	
	public Canvas getCanvas(){ return myCanvas; }
	public ShapeExplorer getShapeExplorer(){ return shapeExpl; }
	public ShapeProperties getShapeProperties(){ return shapeProp; }
	public ShapeTree getShapeTree() { return shapeTree; }
	public ShapePropTable getShapeTable() { return shapeTable; }
}
